module.exports = function (io) {
    var socketList = {};
    var user = {};

    io.sockets.on('connection', function (socket) {
        console.log('链接成功！');
        socket.on('login', (id) => {
            console.log(id, '1111');
            user[id] = socket.id;
            console.log(user);

            socket.name = id;
            socket.emit('login', id)

        });


        //用户一对一消息发送
        socket.on('msg', (msg, fromId, toId) => {
            console.log(msg, user, '1111');
            socket.to(user[toId]).emit('msg', msg, fromId)

        })
        socket.on('disconnecting', () => {
            console.log(socket.id + '离开  ');
            if (user.hasOwnProperty(socket.name)) {
                delete user[socket.name]
            }

        })
    })
}